<?php
namespace Core\Common\Helper;

/**
 * Trait LastError
 * @package App\Helper
 */
trait LastError
{
    protected $lastError;

    /**
     * @return ErrorPack
     */
    public function lastError()
    {
        return $this->lastError;
    }

    /**
     * @param string|ErrorPack $message
     * @param int $code
     * @return ErrorPack
     */
    public function setLastError($message, $code = 10000)
    {
        if ($message instanceof ErrorPack) {
            $this->lastError = $message;
            return $this->lastError;
        }

        $error = new ErrorPack($message, $code);
        $this->lastError = $error;
        return $this->lastError;
    }

}